<!DOCTYPE html>
<html lang="zh-CN">
    <head>
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <meta name="robots" content="noodp" />
        <title>自动化搭建博客工具 - L_B__</title><meta name="referrer" content="no-referrer">
<meta name="description" content="自动化搭建博客工具"><meta property="og:title" content="自动化搭建博客工具" />
<meta property="og:description" content="自动化搭建博客工具" />
<meta property="og:type" content="article" />
<meta property="og:url" content="https://acking-you.github.io/posts/%E8%87%AA%E5%8A%A8%E5%8C%96%E6%90%AD%E5%BB%BA%E5%8D%9A%E5%AE%A2%E5%B7%A5%E5%85%B7/" /><meta property="og:image" content="https://acking-you.github.io/logo.png"/><meta property="article:section" content="posts" />
<meta property="article:published_time" content="2022-02-12T00:00:00+00:00" />
<meta property="article:modified_time" content="2022-02-12T00:00:00+00:00" />

<meta name="twitter:card" content="summary_large_image"/>
<meta name="twitter:image" content="https://acking-you.github.io/logo.png"/>

<meta name="twitter:title" content="自动化搭建博客工具"/>
<meta name="twitter:description" content="自动化搭建博客工具"/>
<meta name="application-name" content="FeelIt">
<meta name="apple-mobile-web-app-title" content="FeelIt"><meta name="theme-color" content="#ffffff"><meta name="msapplication-TileColor" content="#da532c"><link rel="canonical" href="https://acking-you.github.io/posts/%E8%87%AA%E5%8A%A8%E5%8C%96%E6%90%AD%E5%BB%BA%E5%8D%9A%E5%AE%A2%E5%B7%A5%E5%85%B7/" /><link rel="prev" href="https://acking-you.github.io/posts/%E6%95%B0%E6%8D%AE%E5%BA%93%E5%9F%BA%E7%A1%80/" /><link rel="next" href="https://acking-you.github.io/posts/leetcode%E6%AF%8F%E6%97%A5%E4%B8%80%E9%A2%981020%E9%A3%9E%E5%9C%B0%E7%9A%84%E6%95%B0%E9%87%8F/" /><link rel="stylesheet" href="/css/page.min.css"><link rel="stylesheet" href="/css/home.min.css"><script type="application/ld+json">
    {
        "@context": "http://schema.org",
        "@type": "BlogPosting",
        "headline": "自动化搭建博客工具",
        "inLanguage": "zh-CN",
        "mainEntityOfPage": {
            "@type": "WebPage",
            "@id": "https:\/\/acking-you.github.io\/posts\/%E8%87%AA%E5%8A%A8%E5%8C%96%E6%90%AD%E5%BB%BA%E5%8D%9A%E5%AE%A2%E5%B7%A5%E5%85%B7\/"
        },"genre": "posts","keywords": "自动化搭建博客工具","wordcount":  1832 ,
        "url": "https:\/\/acking-you.github.io\/posts\/%E8%87%AA%E5%8A%A8%E5%8C%96%E6%90%AD%E5%BB%BA%E5%8D%9A%E5%AE%A2%E5%B7%A5%E5%85%B7\/","datePublished": "2022-02-12T00:00:00+00:00","dateModified": "2022-02-12T00:00:00+00:00","publisher": {
            "@type": "Organization",
            "name": "作者"},"author": {
                "@type": "Person",
                "name": "作者"
            },"description": "自动化搭建博客工具"
    }
    </script></head><body data-header-desktop="auto" data-header-mobile="auto"><script>(window.localStorage && localStorage.getItem('theme') ? localStorage.getItem('theme') === 'dark' : ('auto' === 'auto' ? window.matchMedia('(prefers-color-scheme: dark)').matches : 'auto' === 'dark')) && document.body.setAttribute('theme', 'dark');</script>

        <div id="mask"></div><div class="wrapper"><header class="desktop" id="header-desktop">
    <div class="header-wrapper">
        <div class="header-title">
            <a href="/" title="L_B__">L_B__</a>
        </div>
        <div class="menu">
            <div class="menu-inner"><a class="menu-item" href="/posts/"> 文章 </a><a class="menu-item" href="/tags/"> 标签 </a><a class="menu-item" href="/categories/"> 分类 </a><span class="menu-item delimiter"></span><span class="menu-item search" id="search-desktop">
                        <input type="text" placeholder="搜索文章标题或内容..." id="search-input-desktop">
                        <a href="#" class="search-button search-toggle" id="search-toggle-desktop" title="搜索">
                            <i class="fas fa-search fa-fw"></i>
                        </a>
                        <a href="#" class="search-button search-clear" id="search-clear-desktop" title="清空">
                            <i class="fas fa-times-circle fa-fw"></i>
                        </a>
                        <span class="search-button search-loading" id="search-loading-desktop">
                            <i class="fas fa-spinner fa-fw fa-spin"></i>
                        </span>
                    </span><a href="javascript:void(0);" class="menu-item theme-switch" title="切换主题">
                    <i class="fas fa-adjust fa-fw"></i>
                </a>
            </div>
        </div>
    </div>
</header><header class="mobile" id="header-mobile">
    <div class="header-container">
        <div class="header-wrapper">
            <div class="header-title">
                <a href="/" title="L_B__">L_B__</a>
            </div>
            <div class="menu-toggle" id="menu-toggle-mobile">
                <span></span><span></span><span></span>
            </div>
        </div>
        <div class="menu" id="menu-mobile"><div class="search-wrapper">
                    <div class="search mobile" id="search-mobile">
                        <input type="text" placeholder="搜索文章标题或内容..." id="search-input-mobile">
                        <a href="#" class="search-button search-toggle" id="search-toggle-mobile" title="搜索">
                            <i class="fas fa-search fa-fw"></i>
                        </a>
                        <a href="#" class="search-button search-clear" id="search-clear-mobile" title="清空">
                            <i class="fas fa-times-circle fa-fw"></i>
                        </a>
                        <span class="search-button search-loading" id="search-loading-mobile">
                            <i class="fas fa-spinner fa-fw fa-spin"></i>
                        </span>
                    </div>
                    <a href="#" class="search-cancel" id="search-cancel-mobile">
                        取消
                    </a>
                </div><a class="menu-item" href="/posts/" title="">文章</a><a class="menu-item" href="/tags/" title="">标签</a><a class="menu-item" href="/categories/" title="">分类</a><div class="menu-item"><a href="javascript:void(0);" class="theme-switch" title="切换主题">
                    <i class="fas fa-adjust fa-fw"></i>
                </a>
            </div></div>
    </div>
</header><div class="search-dropdown desktop">
    <div id="search-dropdown-desktop"></div>
</div>
<div class="search-dropdown mobile">
    <div id="search-dropdown-mobile"></div>
</div><main class="main">
                <div class="container"><div class="toc" id="toc-auto">
            <h2 class="toc-title">目录</h2>
            <div class="toc-content" id="toc-content-auto"></div>
        </div><article class="page single" data-toc="disable"><div class="featured-image"><img
        class="lazyload"
        src="/svg/loading.min.svg"
        data-src="https://img-blog.csdnimg.cn/img_convert/cfdaf87ba57fa1099a94d87809378cbb.png#pic_center"
        data-srcset="https://img-blog.csdnimg.cn/img_convert/cfdaf87ba57fa1099a94d87809378cbb.png#pic_center, https://img-blog.csdnimg.cn/img_convert/cfdaf87ba57fa1099a94d87809378cbb.png#pic_center 1.5x, https://img-blog.csdnimg.cn/img_convert/cfdaf87ba57fa1099a94d87809378cbb.png#pic_center 2x"
        data-sizes="auto"
        alt="https://img-blog.csdnimg.cn/img_convert/cfdaf87ba57fa1099a94d87809378cbb.png#pic_center"
        title="自动化搭建博客工具" /></div><div class="single-card" data-image="true"><h2 class="single-title animated flipInX">自动化搭建博客工具</h2><div class="post-meta">
                <div class="post-meta-line"><span class="post-author"><a href="/" title="Author" rel=" author" class="author"><i class="fas fa-user-circle fa-fw"></i>作者</a></span>&nbsp;<span class="post-category">出版于  <a href="/categories/c++%E5%AE%9E%E6%88%98/"><i class="far fa-folder fa-fw"></i>C++实战</a></span></div>
                <div class="post-meta-line"><span><i class="far fa-calendar-alt fa-fw"></i>&nbsp;<time datetime="2022-02-12">2022-02-12</time></span>&nbsp;<span><i class="fas fa-pencil-alt fa-fw"></i>&nbsp;约 1832 字</span>&nbsp;
                    <span><i class="far fa-clock fa-fw"></i>&nbsp;预计阅读 4 分钟</span>&nbsp;</div>
            </div>
            
            <hr><div class="details toc" id="toc-static"  data-kept="">
                    <div class="details-summary toc-title">
                        <span>目录</span>
                        <span><i class="details-icon fas fa-angle-right"></i></span>
                    </div>
                    <div class="details-content toc-content" id="toc-content-static"><nav id="TableOfContents">
  <ul>
    <li><a href="#软件使用">软件使用</a></li>
    <li><a href="#项目介绍">项目介绍</a></li>
    <li><a href="#项目关键源码">项目关键源码</a></li>
  </ul>
</nav></div>
                </div><div class="content" id="content"><h2 id="软件使用">软件使用</h2>
<blockquote>
<p>使用前请下载好git工具</p>
</blockquote>
<p><a href="https://www.bilibili.com/video/BV11S4y1G7SW" target="_blank" rel="noopener noreffer">视频教程</a></p>
<p><img
        class="lazyload"
        src="/svg/loading.min.svg"
        data-src="https://s2.loli.net/2022/02/09/ieRtSKVh7fCO51A.gif"
        data-srcset="https://s2.loli.net/2022/02/09/ieRtSKVh7fCO51A.gif, https://s2.loli.net/2022/02/09/ieRtSKVh7fCO51A.gif 1.5x, https://s2.loli.net/2022/02/09/ieRtSKVh7fCO51A.gif 2x"
        data-sizes="auto"
        alt="https://s2.loli.net/2022/02/09/ieRtSKVh7fCO51A.gif"
        title="example" /></p>
<h2 id="项目介绍">项目介绍</h2>
<p><a href="https://github.com/ACking-you/AutoHugoSetup" target="_blank" rel="noopener noreffer">项目所在地</a></p>
<blockquote>
<p>温馨提示：本地搭建完网站框架后，每次新建文章的写作体验较差，可以看看我的另一个 <a href="https://github.com/ACking-you/AutoHugoWrite" target="_blank" rel="noopener noreffer">hugo 博客自动化写作工具</a></p>
</blockquote>
<p><img
        class="lazyload"
        src="/svg/loading.min.svg"
        data-src="https://s2.loli.net/2022/02/09/o4FSRsvbk1E96Wu.png"
        data-srcset="https://s2.loli.net/2022/02/09/o4FSRsvbk1E96Wu.png, https://s2.loli.net/2022/02/09/o4FSRsvbk1E96Wu.png 1.5x, https://s2.loli.net/2022/02/09/o4FSRsvbk1E96Wu.png 2x"
        data-sizes="auto"
        alt="https://s2.loli.net/2022/02/09/o4FSRsvbk1E96Wu.png"
        title="AutoHugoSetup" /></p>
<p>src目录：存放图形化项目的源代码，使用 Qt6 可直接启动 QHugoInit 项目。</p>
<p>bin目录：存放项目的可执行二进制文件。</p>
<ul>
<li>exec_code.bat：用于写入代码执行脚本</li>
<li>hugo.exe：构建博客的基石</li>
<li>QHugoInit.exe：软件启动程序</li>
<li>log.txt：整个程序执行的日志</li>
</ul>
<h2 id="项目关键源码">项目关键源码</h2>
<blockquote>
<p>通过多线程防止下载步骤把画面给阻塞</p>
</blockquote>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-cpp" data-lang="cpp"><span class="c1">//TODO 简单封装一个用于多线程通信的类
</span><span class="c1"></span><span class="k">class</span> <span class="nc">run_thread</span><span class="o">:</span><span class="k">public</span> <span class="n">QThread</span><span class="p">{</span>
<span class="k">public</span><span class="o">:</span>
    <span class="n">run_thread</span><span class="p">()</span> <span class="o">=</span> <span class="k">delete</span><span class="p">;</span>
    <span class="n">run_thread</span><span class="p">(</span><span class="k">const</span> <span class="n">std</span><span class="o">::</span><span class="n">function</span><span class="o">&lt;</span><span class="kt">void</span><span class="p">()</span><span class="o">&gt;&amp;</span><span class="n">Runnable</span><span class="p">,</span><span class="n">QObject</span><span class="o">*</span> <span class="n">parent</span> <span class="o">=</span> <span class="k">nullptr</span><span class="p">)</span><span class="o">:</span><span class="n">m_task</span><span class="p">(</span><span class="k">nullptr</span><span class="p">){</span>
        <span class="n">m_task</span> <span class="o">=</span> <span class="n">Runnable</span><span class="p">;</span>
    <span class="p">}</span>
    <span class="kt">void</span> <span class="nf">run</span><span class="p">()</span><span class="k">override</span><span class="p">{</span>
        <span class="k">if</span><span class="p">(</span><span class="n">m_task</span><span class="o">!=</span><span class="k">nullptr</span><span class="p">);</span>
            <span class="n">m_task</span><span class="p">();</span>
    <span class="p">}</span>
<span class="k">private</span><span class="o">:</span>
    <span class="n">std</span><span class="o">::</span><span class="n">function</span><span class="o">&lt;</span><span class="kt">void</span><span class="p">()</span><span class="o">&gt;</span><span class="n">m_task</span><span class="p">;</span>
<span class="p">};</span>
</code></pre></div><blockquote>
<p>通过文件io控制命令行的代码执行来执行对应的每一步</p>
</blockquote>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-cpp" data-lang="cpp"><span class="kt">void</span> <span class="n">MainWindow</span><span class="o">::</span><span class="n">on_right_Btn_clicked</span><span class="p">()</span>
<span class="p">{</span>
    <span class="k">auto</span> <span class="n">path</span> <span class="o">=</span> <span class="n">ui</span><span class="o">-&gt;</span><span class="n">input</span><span class="o">-&gt;</span><span class="n">text</span><span class="p">();</span>
    <span class="k">if</span><span class="p">(</span><span class="o">!</span><span class="n">QDir</span><span class="p">(</span><span class="n">path</span><span class="p">).</span><span class="n">exists</span><span class="p">()</span><span class="o">||</span><span class="n">path</span><span class="p">.</span><span class="n">isEmpty</span><span class="p">()){</span>
        <span class="n">QMessageBox</span><span class="o">::</span><span class="n">warning</span><span class="p">(</span><span class="k">nullptr</span><span class="p">,</span><span class="s">&#34;提示&#34;</span><span class="p">,</span><span class="s">&#34;文件夹路径不存在&#34;</span><span class="p">);</span>
        <span class="k">return</span><span class="p">;</span>
    <span class="p">}</span>
    <span class="n">ui</span><span class="o">-&gt;</span><span class="n">w2</span><span class="o">-&gt;</span><span class="n">setVisible</span><span class="p">(</span><span class="nb">false</span><span class="p">);</span>
    <span class="n">ui</span><span class="o">-&gt;</span><span class="n">w4</span><span class="o">-&gt;</span><span class="n">setVisible</span><span class="p">(</span><span class="nb">false</span><span class="p">);</span>
    <span class="n">ui</span><span class="o">-&gt;</span><span class="n">w3</span><span class="o">-&gt;</span><span class="n">setVisible</span><span class="p">(</span><span class="nb">true</span><span class="p">);</span>
    <span class="n">ui</span><span class="o">-&gt;</span><span class="n">l1</span><span class="o">-&gt;</span><span class="n">setText</span><span class="p">(</span><span class="s">&#34;一切即将准备就绪&#34;</span><span class="p">);</span>
    <span class="n">ui</span><span class="o">-&gt;</span><span class="n">l2</span><span class="o">-&gt;</span><span class="n">setText</span><span class="p">(</span><span class="s">&#34;正在初始化您的hugo网站&#34;</span><span class="p">);</span>
    <span class="n">ui</span><span class="o">-&gt;</span><span class="n">l3</span><span class="o">-&gt;</span><span class="n">setOpenExternalLinks</span><span class="p">(</span><span class="nb">true</span><span class="p">);</span>
    <span class="n">ui</span><span class="o">-&gt;</span><span class="n">l3</span><span class="o">-&gt;</span><span class="n">setText</span><span class="p">(</span><span class="n">R</span><span class="s">&#34;(&lt;html&gt;    &lt;style&gt;</span>
                    <span class="n">a</span> <span class="p">{</span>
                        <span class="nl">color</span><span class="p">:</span><span class="err">#</span><span class="mi">3281</span><span class="n">b8</span><span class="p">;</span>
                    <span class="p">}</span>
                <span class="o">&lt;/</span><span class="n">style</span><span class="o">&gt;&lt;</span><span class="n">head</span><span class="o">/&gt;&lt;</span><span class="n">body</span><span class="o">&gt;&lt;</span><span class="n">p</span><span class="o">&gt;</span><span class="err">这可能会耗费几分钟，请不要强制关闭应用程序</span><span class="o">&lt;</span><span class="n">br</span><span class="o">/&gt;&lt;</span><span class="n">br</span><span class="o">/&gt;</span><span class="err">闲得无聊？</span><span class="o">&lt;</span><span class="n">a</span> <span class="n">href</span><span class="o">=</span><span class="s">&#34;https://github.com/ACking-you/AutoHugoSetup&#34;</span><span class="o">&gt;</span><span class="err">给个</span><span class="n">star</span><span class="o">&lt;/</span><span class="n">a</span><span class="o">&gt;&lt;/</span><span class="n">p</span><span class="o">&gt;&lt;/</span><span class="n">body</span><span class="o">&gt;&lt;/</span><span class="n">html</span><span class="o">&gt;</span><span class="p">)</span><span class="s">&#34;);</span>
    <span class="n">QProcess</span> <span class="n">qp</span><span class="p">;</span>
    <span class="n">std</span><span class="o">::</span><span class="n">ofstream</span> <span class="n">writer</span><span class="p">;</span>
    <span class="n">m_Path</span> <span class="o">=</span> <span class="n">path</span><span class="p">;</span>
    <span class="k">auto</span> <span class="n">std_str</span> <span class="o">=</span> <span class="n">m_Path</span><span class="p">.</span><span class="n">toStdString</span><span class="p">();</span>

    <span class="c1">//first step
</span><span class="c1"></span>    <span class="n">writer</span><span class="p">.</span><span class="n">open</span><span class="p">(</span><span class="s">&#34;./exec_code.bat&#34;</span><span class="p">);</span>
    <span class="k">if</span><span class="p">(</span><span class="o">!</span><span class="n">writer</span><span class="p">.</span><span class="n">is_open</span><span class="p">()){</span>
        <span class="n">QMessageBox</span><span class="o">::</span><span class="n">warning</span><span class="p">(</span><span class="k">nullptr</span><span class="p">,</span><span class="s">&#34;提示&#34;</span><span class="p">,</span><span class="s">&#34;第一次写入文件打开失败&#34;</span><span class="p">);</span>
        <span class="n">writer</span><span class="p">.</span><span class="n">close</span><span class="p">();</span>
        <span class="n">QCoreApplication</span><span class="o">::</span><span class="n">exit</span><span class="p">(</span><span class="mi">1</span><span class="p">);</span>
    <span class="p">}</span>
    <span class="n">ui</span><span class="o">-&gt;</span><span class="n">info_text</span><span class="o">-&gt;</span><span class="n">setText</span><span class="p">(</span><span class="s">&#34;正在初始化 hugo 博客&#34;</span><span class="p">);</span>
    <span class="n">std</span><span class="o">::</span><span class="n">replace</span><span class="p">(</span><span class="n">std_str</span><span class="p">.</span><span class="n">begin</span><span class="p">(),</span><span class="n">std_str</span><span class="p">.</span><span class="n">end</span><span class="p">(),</span><span class="sc">&#39;/&#39;</span><span class="p">,</span><span class="sc">&#39;\\&#39;</span><span class="p">);</span>   <span class="c1">//这里注意：cmd32命令只支持反斜杠！
</span><span class="c1"></span>    <span class="n">writer</span><span class="o">&lt;&lt;</span><span class="n">R</span><span class="s">&#34;(chcp 65001)&#34;</span><span class="o">&lt;&lt;</span><span class="sc">&#39;\n&#39;</span><span class="p">;</span>                      <span class="c1">//设置编码为utf-8
</span><span class="c1"></span>    <span class="n">writer</span><span class="o">&lt;&lt;</span><span class="n">R</span><span class="s">&#34;(copy .\hugo.exe )&#34;</span><span class="o">&lt;&lt;</span><span class="n">std_str</span><span class="o">&lt;&lt;</span><span class="sc">&#39;\n&#39;</span><span class="p">;</span>       <span class="c1">//copy一份hugo.exe到目标目录下
</span><span class="c1"></span>    <span class="n">writer</span><span class="o">&lt;&lt;</span><span class="s">&#34;cd /d&#34;</span><span class="o">&lt;&lt;</span><span class="n">std_str</span><span class="o">&lt;&lt;</span><span class="sc">&#39;\n&#39;</span><span class="p">;</span>                     <span class="c1">//切换到创建目录，这里/d代表直接一步到位的切换目录
</span><span class="c1"></span>    <span class="n">writer</span><span class="o">&lt;&lt;</span><span class="n">R</span><span class="s">&#34;(.\hugo new site myBlog)&#34;</span><span class="o">&lt;&lt;</span><span class="sc">&#39;\n&#39;</span><span class="p">;</span>          <span class="c1">//初始化hugo命令
</span><span class="c1"></span>    <span class="n">writer</span><span class="p">.</span><span class="n">close</span><span class="p">();</span>
    <span class="n">qp</span><span class="p">.</span><span class="n">startCommand</span><span class="p">(</span><span class="n">R</span><span class="s">&#34;(.\exec_code.bat)&#34;</span><span class="p">);</span>
    <span class="k">if</span><span class="p">(</span><span class="n">qp</span><span class="p">.</span><span class="n">waitForFinished</span><span class="p">()){</span>
        <span class="n">QString</span> <span class="n">str</span> <span class="o">=</span> <span class="n">qp</span><span class="p">.</span><span class="n">readAll</span><span class="p">();</span>
        <span class="n">m_logWriter</span><span class="o">&lt;&lt;</span><span class="s">&#34;-----1st step-----</span><span class="se">\n\r</span><span class="s">&#34;</span><span class="o">&lt;&lt;</span><span class="n">str</span><span class="p">.</span><span class="n">toStdString</span><span class="p">()</span><span class="o">&lt;&lt;</span><span class="sc">&#39;\n&#39;</span><span class="p">;</span>
        <span class="n">ui</span><span class="o">-&gt;</span><span class="n">info_text</span><span class="o">-&gt;</span><span class="n">setText</span><span class="p">(</span><span class="s">&#34; hugo 博客初始化完成&#34;</span><span class="p">);</span>
    <span class="p">}</span>

    <span class="c1">//second step：执行此步之前先判断git是否可用，此步执行时间最久，不要让它卡死主线程，故需要用到多线程技术
</span><span class="c1"></span>    <span class="n">qp</span><span class="p">.</span><span class="n">startCommand</span><span class="p">(</span><span class="s">&#34;git&#34;</span><span class="p">);</span>
    <span class="k">if</span><span class="p">(</span><span class="o">!</span><span class="n">qp</span><span class="p">.</span><span class="n">waitForFinished</span><span class="p">()){</span>
        <span class="n">QMessageBox</span><span class="o">::</span><span class="n">warning</span><span class="p">(</span><span class="k">nullptr</span><span class="p">,</span><span class="s">&#34;提示&#34;</span><span class="p">,</span><span class="s">&#34;未安装git工具或未设置到环境变量&#34;</span><span class="p">);</span>
        <span class="n">QCoreApplication</span><span class="o">::</span><span class="n">exit</span><span class="p">(</span><span class="mi">1</span><span class="p">);</span>
    <span class="p">}</span>
    <span class="n">writer</span><span class="p">.</span><span class="n">open</span><span class="p">(</span><span class="s">&#34;./exec_code.bat&#34;</span><span class="p">);</span>
    <span class="k">if</span><span class="p">(</span><span class="o">!</span><span class="n">writer</span><span class="p">.</span><span class="n">is_open</span><span class="p">()){</span>
        <span class="n">QMessageBox</span><span class="o">::</span><span class="n">warning</span><span class="p">(</span><span class="k">nullptr</span><span class="p">,</span><span class="s">&#34;提示&#34;</span><span class="p">,</span><span class="s">&#34;第二次写入文件打开失败&#34;</span><span class="p">);</span>
        <span class="n">writer</span><span class="p">.</span><span class="n">close</span><span class="p">();</span>
        <span class="n">QCoreApplication</span><span class="o">::</span><span class="n">exit</span><span class="p">(</span><span class="mi">1</span><span class="p">);</span>
    <span class="p">}</span>
    <span class="n">ui</span><span class="o">-&gt;</span><span class="n">info_text</span><span class="o">-&gt;</span><span class="n">setText</span><span class="p">(</span><span class="s">&#34;正在下载 FeelIt 主题&#34;</span><span class="p">);</span>
    <span class="n">std</span><span class="o">::</span><span class="n">filesystem</span><span class="o">::</span><span class="n">path</span> <span class="n">blog_path</span> <span class="o">=</span> <span class="n">std_str</span><span class="p">;</span>
    <span class="n">blog_path</span> <span class="o">/=</span> <span class="s">&#34;myBlog&#34;</span><span class="p">;</span>
    <span class="n">m_Path</span> <span class="o">=</span> <span class="n">blog_path</span><span class="p">.</span><span class="n">string</span><span class="p">().</span><span class="n">c_str</span><span class="p">();</span>
    <span class="n">writer</span><span class="o">&lt;&lt;</span><span class="s">&#34;cd /d&#34;</span><span class="o">&lt;&lt;</span><span class="n">blog_path</span><span class="o">&lt;&lt;</span><span class="s">&#34;</span><span class="se">\\</span><span class="s">themes&#34;</span><span class="o">&lt;&lt;</span><span class="sc">&#39;\n&#39;</span><span class="p">;</span>           <span class="c1">//cd到themes文件夹目录下
</span><span class="c1"></span>    <span class="n">writer</span><span class="o">&lt;&lt;</span><span class="s">&#34;git clone https://gitee.com/acking-you/FeelIt.git&#34;</span><span class="o">&lt;&lt;</span><span class="sc">&#39;\n&#39;</span><span class="p">;</span><span class="c1">//开始通过git下载主题包
</span><span class="c1"></span>    <span class="n">writer</span><span class="p">.</span><span class="n">close</span><span class="p">();</span>
    <span class="n">QThread</span><span class="o">*</span> <span class="n">sub_thread</span> <span class="o">=</span> <span class="k">new</span> <span class="n">run_thread</span><span class="p">([</span><span class="o">&amp;</span><span class="p">]{</span>   <span class="c1">//最耗时间的工作别去干扰主线程的正常运行，否则主线程可能看起来会陷入瘫痪
</span><span class="c1"></span>        <span class="n">QProcess</span> <span class="n">tqp</span><span class="p">;</span>
        <span class="c1">//信号槽机制，主线程等待子线程完成任务发送信号后再执行最后的步骤，因为这个过程肯定是要同步进行，故需要信号槽来等待
</span><span class="c1"></span>        <span class="n">connect</span><span class="p">(</span><span class="o">&amp;</span><span class="n">tqp</span><span class="p">,</span><span class="o">&amp;</span><span class="n">QProcess</span><span class="o">::</span><span class="n">finished</span><span class="p">,[</span><span class="o">&amp;</span><span class="p">](</span><span class="kt">int</span> <span class="n">exitCode</span><span class="p">,</span> <span class="n">QProcess</span><span class="o">::</span><span class="n">ExitStatus</span> <span class="n">exitStatus</span><span class="p">){</span>
            <span class="c1">//step third
</span><span class="c1"></span>            <span class="n">std</span><span class="o">::</span><span class="n">ofstream</span> <span class="n">writer</span><span class="p">;</span>
            <span class="n">QProcess</span> <span class="n">qp</span><span class="p">;</span>
            <span class="n">writer</span><span class="p">.</span><span class="n">open</span><span class="p">(</span><span class="s">&#34;./exec_code.bat&#34;</span><span class="p">);</span>
            <span class="k">if</span><span class="p">(</span><span class="o">!</span><span class="n">writer</span><span class="p">.</span><span class="n">is_open</span><span class="p">()){</span>
                <span class="n">QMessageBox</span><span class="o">::</span><span class="n">warning</span><span class="p">(</span><span class="k">nullptr</span><span class="p">,</span><span class="s">&#34;提示&#34;</span><span class="p">,</span><span class="s">&#34;第三次写入文件打开失败&#34;</span><span class="p">);</span>
                <span class="n">writer</span><span class="p">.</span><span class="n">close</span><span class="p">();</span>
                <span class="n">QCoreApplication</span><span class="o">::</span><span class="n">exit</span><span class="p">(</span><span class="mi">1</span><span class="p">);</span>
            <span class="p">}</span>
            <span class="n">ui</span><span class="o">-&gt;</span><span class="n">info_text</span><span class="o">-&gt;</span><span class="n">setText</span><span class="p">(</span><span class="s">&#34;配置本地主题中...&#34;</span><span class="p">);</span>
            <span class="n">writer</span><span class="o">&lt;&lt;</span><span class="s">&#34;cd /d&#34;</span><span class="o">&lt;&lt;</span><span class="n">m_Path</span><span class="p">.</span><span class="n">toStdString</span><span class="p">()</span><span class="o">&lt;&lt;</span><span class="sc">&#39;\n&#39;</span><span class="p">;</span>       <span class="c1">//cd到blog_path
</span><span class="c1"></span>            <span class="n">writer</span><span class="o">&lt;&lt;</span><span class="n">R</span><span class="s">&#34;(del .\config.toml)&#34;</span><span class="o">&lt;&lt;</span><span class="sc">&#39;\n&#39;</span><span class="p">;</span>      <span class="c1">//删除原本的config文件
</span><span class="c1"></span>            <span class="n">writer</span><span class="o">&lt;&lt;</span><span class="n">R</span><span class="s">&#34;(move .</span><span class="se">\t</span><span class="s">hemes\FeelIt\config.toml .\)&#34;</span><span class="o">&lt;&lt;</span><span class="sc">&#39;\n&#39;</span><span class="p">;</span>  <span class="c1">//将我的配置文件放到顶级目录去
</span><span class="c1"></span>            <span class="n">writer</span><span class="o">&lt;&lt;</span><span class="n">R</span><span class="s">&#34;(move .</span><span class="se">\t</span><span class="s">hemes\FeelIt\exampleSite\static\*  .\static\)&#34;</span><span class="o">&lt;&lt;</span><span class="sc">&#39;\n&#39;</span><span class="p">;</span><span class="c1">//移动static图片资源
</span><span class="c1"></span>            <span class="n">writer</span><span class="o">&lt;&lt;</span><span class="n">R</span><span class="s">&#34;(move ..\hugo.exe .\)&#34;</span><span class="o">&lt;&lt;</span><span class="sc">&#39;\n&#39;</span><span class="p">;</span><span class="c1">//将之前的hugo.exe移动到真正的博客目录下
</span><span class="c1"></span>            <span class="n">writer</span><span class="o">&lt;&lt;</span><span class="n">R</span><span class="s">&#34;(mkdir .\content\posts)&#34;</span><span class="o">&lt;&lt;</span><span class="sc">&#39;\n&#39;</span><span class="p">;</span>  <span class="c1">//创建用于写文章的目录
</span><span class="c1"></span>            <span class="n">writer</span><span class="p">.</span><span class="n">close</span><span class="p">();</span>
            <span class="n">qp</span><span class="p">.</span><span class="n">startCommand</span><span class="p">(</span><span class="n">R</span><span class="s">&#34;(.\exec_code.bat)&#34;</span><span class="p">);</span>
            <span class="k">if</span><span class="p">(</span><span class="n">qp</span><span class="p">.</span><span class="n">waitForFinished</span><span class="p">(</span><span class="mi">120000</span><span class="p">)){</span>
                <span class="n">ui</span><span class="o">-&gt;</span><span class="n">info_text</span><span class="o">-&gt;</span><span class="n">setText</span><span class="p">(</span><span class="s">&#34;配置完成   &#34;</span><span class="p">);</span>
                <span class="n">ending</span><span class="p">();</span>
                <span class="n">m_logWriter</span><span class="o">&lt;&lt;</span><span class="s">&#34;-----3rd step-----</span><span class="se">\n\r</span><span class="s">&#34;</span><span class="o">&lt;&lt;</span><span class="n">qp</span><span class="p">.</span><span class="n">readAll</span><span class="p">().</span><span class="n">toStdString</span><span class="p">();</span>
            <span class="p">}</span>
        <span class="p">});</span>
        <span class="n">tqp</span><span class="p">.</span><span class="n">startCommand</span><span class="p">(</span><span class="n">R</span><span class="s">&#34;(.\exec_code.bat)&#34;</span><span class="p">);</span>

        <span class="k">if</span><span class="p">(</span><span class="o">!</span><span class="n">tqp</span><span class="p">.</span><span class="n">waitForFinished</span><span class="p">(</span><span class="mi">120000</span><span class="p">)){</span>
            <span class="n">QMessageBox</span><span class="o">::</span><span class="n">warning</span><span class="p">(</span><span class="k">nullptr</span><span class="p">,</span><span class="s">&#34;提示&#34;</span><span class="p">,</span><span class="s">&#34;下载主题响应超时&#34;</span><span class="p">);</span>
            <span class="n">QCoreApplication</span><span class="o">::</span><span class="n">exit</span><span class="p">(</span><span class="mi">1</span><span class="p">);</span>
        <span class="p">}</span><span class="k">else</span><span class="p">{</span>
            <span class="n">m_logWriter</span><span class="o">&lt;&lt;</span><span class="s">&#34;-----2nd step-----</span><span class="se">\n\r</span><span class="s">&#34;</span><span class="o">&lt;&lt;</span><span class="n">tqp</span><span class="p">.</span><span class="n">readAll</span><span class="p">().</span><span class="n">toStdString</span><span class="p">();</span>
        <span class="p">}</span>
    <span class="p">});</span>
    <span class="n">sub_thread</span><span class="o">-&gt;</span><span class="n">start</span><span class="p">();</span>
<span class="p">}</span>
</code></pre></div></div><div class="post-footer" id="post-footer">
    <div class="post-info"><div class="post-info-tag"><span><a href="/tags/%E8%87%AA%E5%8A%A8%E5%8C%96%E6%90%AD%E5%BB%BA%E5%8D%9A%E5%AE%A2%E5%B7%A5%E5%85%B7/">自动化搭建博客工具</a>
                </span></div><div class="post-info-line"><div class="post-info-mod">
                <span>更新于 2022-02-12</span>
            </div><div class="post-info-mod"></div>
        </div><div class="post-info-share">
            <span><a href="javascript:void(0);" title="分享到 Twitter" data-sharer="twitter" data-url="https://acking-you.github.io/posts/%E8%87%AA%E5%8A%A8%E5%8C%96%E6%90%AD%E5%BB%BA%E5%8D%9A%E5%AE%A2%E5%B7%A5%E5%85%B7/" data-title="自动化搭建博客工具" data-hashtags="自动化搭建博客工具"><i class="fab fa-twitter fa-fw"></i></a><a href="javascript:void(0);" title="分享到 Facebook" data-sharer="facebook" data-url="https://acking-you.github.io/posts/%E8%87%AA%E5%8A%A8%E5%8C%96%E6%90%AD%E5%BB%BA%E5%8D%9A%E5%AE%A2%E5%B7%A5%E5%85%B7/" data-hashtag="自动化搭建博客工具"><i class="fab fa-facebook-square fa-fw"></i></a><a href="javascript:void(0);" title="分享到 WhatsApp" data-sharer="whatsapp" data-url="https://acking-you.github.io/posts/%E8%87%AA%E5%8A%A8%E5%8C%96%E6%90%AD%E5%BB%BA%E5%8D%9A%E5%AE%A2%E5%B7%A5%E5%85%B7/" data-title="自动化搭建博客工具" data-web><i class="fab fa-whatsapp fa-fw"></i></a><a href="javascript:void(0);" title="分享到 Line" data-sharer="line" data-url="https://acking-you.github.io/posts/%E8%87%AA%E5%8A%A8%E5%8C%96%E6%90%AD%E5%BB%BA%E5%8D%9A%E5%AE%A2%E5%B7%A5%E5%85%B7/" data-title="自动化搭建博客工具"><i class="fab fa-line fa-fw"></i></a><a href="javascript:void(0);" title="分享到 微博" data-sharer="weibo" data-url="https://acking-you.github.io/posts/%E8%87%AA%E5%8A%A8%E5%8C%96%E6%90%AD%E5%BB%BA%E5%8D%9A%E5%AE%A2%E5%B7%A5%E5%85%B7/" data-title="自动化搭建博客工具" data-image="https://img-blog.csdnimg.cn/img_convert/cfdaf87ba57fa1099a94d87809378cbb.png#pic_center"><i class="fab fa-weibo fa-fw"></i></a><a href="javascript:void(0);" title="分享到 Myspace" data-sharer="myspace" data-url="https://acking-you.github.io/posts/%E8%87%AA%E5%8A%A8%E5%8C%96%E6%90%AD%E5%BB%BA%E5%8D%9A%E5%AE%A2%E5%B7%A5%E5%85%B7/" data-title="自动化搭建博客工具" data-description="自动化搭建博客工具"><i data-svg-src="/lib/simple-icons/icons/myspace.min.svg"></i></a><a href="javascript:void(0);" title="分享到 Blogger" data-sharer="blogger" data-url="https://acking-you.github.io/posts/%E8%87%AA%E5%8A%A8%E5%8C%96%E6%90%AD%E5%BB%BA%E5%8D%9A%E5%AE%A2%E5%B7%A5%E5%85%B7/" data-title="自动化搭建博客工具" data-description="自动化搭建博客工具"><i class="fab fa-blogger fa-fw"></i></a><a href="javascript:void(0);" title="分享到 Evernote" data-sharer="evernote" data-url="https://acking-you.github.io/posts/%E8%87%AA%E5%8A%A8%E5%8C%96%E6%90%AD%E5%BB%BA%E5%8D%9A%E5%AE%A2%E5%B7%A5%E5%85%B7/" data-title="自动化搭建博客工具"><i class="fab fa-evernote fa-fw"></i></a></span>
        </div></div><div class="post-nav"><a href="/posts/%E6%95%B0%E6%8D%AE%E5%BA%93%E5%9F%BA%E7%A1%80/" class="prev" rel="prev" title="数据库基础"><i class="fas fa-angle-left fa-fw"></i>Previous Post</a>
            <a href="/posts/leetcode%E6%AF%8F%E6%97%A5%E4%B8%80%E9%A2%981020%E9%A3%9E%E5%9C%B0%E7%9A%84%E6%95%B0%E9%87%8F/" class="next" rel="next" title="并查集/dfs解决——leetcode每日一题——1020飞地的数量">Next Post<i class="fas fa-angle-right fa-fw"></i></a></div></div>
</div></article></div>
            </main>
            <footer class="footer"><div class="footer-container"><div class="footer-line">由 <a href="https://gohugo.io/" target="_blank" rel="noopener noreffer" title="Hugo 0.86.0">Hugo</a> 强力驱动 | 主题 - <a href="https://github.com/khusika/FeelIt" target="_blank" rel="noopener noreffer" title="FeelIt 1.0.1"><i class="fas fa-hand-holding-heart fa-fw"></i> FeelIt</a>
        </div><div class="footer-line" itemscope itemtype="http://schema.org/CreativeWork"><i class="far fa-copyright fa-fw"></i><span itemprop="copyrightYear">2023</span><span class="author" itemprop="copyrightHolder">&nbsp;<a href="/"></a></span></div>
</div>
</footer>
        </div>

        <div id="fixed-buttons"><a href="#" id="back-to-top" class="fixed-button" title="回到顶部">
                <i class="fas fa-chevron-up fa-fw"></i>
            </a></div><link rel="stylesheet" href="/lib/fontawesome-free/all.min.css"><link rel="stylesheet" href="/lib/animate/animate.min.css"><link rel="stylesheet" href="/lib/katex/katex.min.css"><link rel="stylesheet" href="/lib/katex/copy-tex.min.css"><script src="/lib/autocomplete/autocomplete.min.js"></script><script src="/lib/lunr/lunr.min.js"></script><script src="/lib/lunr/lunr.stemmer.support.min.js"></script><script src="/lib/lunr/lunr.zh.min.js"></script><script src="/lib/lazysizes/lazysizes.min.js"></script><script src="/lib/clipboard/clipboard.min.js"></script><script src="/lib/sharer/sharer.min.js"></script><script src="/lib/katex/katex.min.js"></script><script src="/lib/katex/auto-render.min.js"></script><script src="/lib/katex/copy-tex.min.js"></script><script src="/lib/katex/mhchem.min.js"></script><script>window.config={"code":{"copyTitle":"复制到剪贴板","maxShownLines":200},"comment":{},"math":{"delimiters":[{"display":true,"left":"$$","right":"$$"},{"display":true,"left":"\\[","right":"\\]"},{"display":false,"left":"$","right":"$"},{"display":false,"left":"\\(","right":"\\)"}],"strict":false},"search":{"highlightTag":"em","lunrIndexURL":"/index.json","lunrLanguageCode":"zh","lunrSegmentitURL":"/lib/lunr/lunr.segmentit.js","maxResultLength":100,"noResultsFound":"没有找到结果","snippetLength":50,"type":"lunr"}};</script><script src="/js/theme.min.js"></script></body></html>
